package com.bean.activiti.controller;

import com.bean.activiti.entity.VacTask;
import com.bean.activiti.entity.Vacation;
import com.bean.activiti.service.impl.VacationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author Gavin Lee
 * @version 1.0
 * @date 2020-09-18 12:26
 * @desc
 */
@RestController
public class VacationController {

    @Resource
    private VacationService vacationService;

    /**
     * 创建请假单
     */
    @PostMapping("/startVac")
    public Object startVac(@RequestBody Vacation vac, HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return vacationService.startVac(userName, vac);
    }

    /**
     * 我的正在申请的假
     * @param session
     * @return
     */
    @GetMapping("/myVac")
    public Object myVac(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return vacationService.myVac(userName);
    }

    /**
     * 待我审核的请假单
     * @param session
     * @return
     */
    @GetMapping("/myAudit")
    public Object myAudit(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return vacationService.myAudit(userName);
    }

    /**
     * 审核操作-1：通过  | 0：拒绝
     * @param session
     * @param vacTask
     * @return
     */
    @PostMapping("/passAudit")
    public Object passAudit(HttpSession session, @RequestBody VacTask vacTask) {
        String userName = (String) session.getAttribute("userName");
        return vacationService.passAudit(userName, vacTask);
    }

    /**
     * 我申请过的假
     * @param session
     * @return
     */
    @GetMapping("/myVacRecord")
    public Object myVacRecord(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return vacationService.myVacRecord(userName);
    }

    /**
     * 我的审核记录
     * @param session
     * @return
     */
    @GetMapping("/myAuditRecord")
    public Object myAuditRecord(HttpSession session) {
        String userName = (String) session.getAttribute("userName");
        return vacationService.myAuditRecord(userName);
    }

    /**
     * 删除已部署的流程
     * @param procinstId
     * @return
     */
    @GetMapping("/deleteMyVac/{procinstId}")
    public String deleteMyVac(@PathVariable Integer procinstId) {
        vacationService.deleteProcess(String.valueOf(procinstId));
        return "删除成功";
    }

    /**
     * 删除流程定义
     * @param deploymentId
     * @return
     */
    @GetMapping("/delete/{deploymentId}")
    public String deleteDeployment(@PathVariable Integer deploymentId) {
        vacationService.deleteDeployment(String.valueOf(deploymentId));
        return "删除成功";
    }

    /**
     * 获取流程图图片
     */
    @ResponseBody
    @GetMapping("/showProcessImage/{procinstId}")
    public String displayFlowCurrPicnew(@PathVariable String procinstId){
        String image = vacationService.getProcessImage(procinstId);
        return image;
    }

}
